import { Component, OnInit } from '@angular/core';
import { ActivatedRoute,Router } from '@angular/router';
import { RepairService } from "../../repair.service";
@Component({
  selector: 'app-record-detail',
  templateUrl: './record-detail.component.html',
  styleUrls: ['./record-detail.component.css',
    '../../../../../assets/css/timeline.css']
})
export class RecordDetailComponent implements OnInit {
  recordId:string = '';
  data:any;
  detailData:any;
  readOnly:boolean = true;
  constructor(private activeRoute:ActivatedRoute,
              private repairService:RepairService) { }

  ngOnInit() {
    this.activeRoute.params.subscribe(
      params=> {
        this.recordId = this.repairService.orderId = params['recordId'];
        this.repairService.getData().subscribe(res => {
          this.data = res.result;
        }, err => console.log(err));

        this.repairService.getDetailData().subscribe(res => {
          if(res.result!=null){
            this.detailData = res.result;

            if(this.detailData.jiejing){
              this.detailData.jiejing.jjys = this.secondToDate(this.detailData.jiejing.jjhs);
            }
            if(this.detailData.wg){
              this.detailData.wg.wgys = this.secondToDate(this.detailData.wg.wghs);
              this.detailData.wg.dchys = this.secondToDate(this.detailData.wg.dchs);
            }
          }
        }, err => console.log(err));
      }
    );
  }

  cancel(){
    this.repairService.cancel('record');
  }

  secondToDate(msd) {
    let time = msd;
    if (time) {
      let days = Math.floor(time / 86400);
      let hours =  Math.floor(time / 3600 - days * 24);
      let minutes = Math.floor(time / 60 - days * 1440 - hours * 60);
      let seconds = Math.floor(time - days * 86400 - hours * 3600 - minutes * 60);
      return days+'天'+hours+'小时'+minutes+'分钟'+seconds+'秒';
    }
    return time;
  }



}
